﻿/**************************************************************
 *职位申请
 *
 *  Version              CreateBy                 CreateOn
 *  1.0                  hulei                    2012-11-25
 * 
 *****************************************************************/  
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Forest.Cat.Domain;
using Forest.Cat.Domain.Services.Applications;
using Forest.Cat.Admin.Models;
using Forest.Cat.Admin.Models.Applications;
using Forest.Cat.Domain.Entities;
using Forest.Cat.Domain.Services.Compnaies;
using Forest.Cat.Domain.Services;
using Forest.Cat.Domain.Services.JobHunting;
using Forest.Cat.Admin.Models.JobHunting;

namespace Forest.Cat.Admin.Controllers
{
    public class ConcernedJobsController : BaseController
    {
        private readonly IWorkContext _workcontext;
        private readonly ISavedJobService _savedJobService;
        private readonly ICompanyService _companyService;
        private readonly IResumeService _resumeService;
        private const int _pageSize = 10;

        public ConcernedJobsController(IWorkContext workcontext, ISavedJobService savedJobService,
            ICompanyService companyService,IResumeService resumeService)
        {
            this._savedJobService = savedJobService;
            this._workcontext = workcontext;
            this._companyService = companyService;
            this._resumeService = resumeService;
        }

        public ActionResult List(PagingFilteringModel command)
        {
            var model = new SavedJobListModel();

            // 设置默认的Page信息
            if (command.PageSize <= 0) command.PageSize = 20;
            if (command.PageNumber <= 0) command.PageNumber = 1;

            //var id = _workcontext.CurrentUser.Id;
            var id = new Guid("00000000-0000-0000-0000-000001014331");
            var list = _savedJobService.GetApplicationsByJobseekerId(id,
                command.PageNumber - 1, command.PageSize);
            model.PagingFilteringContext.LoadPagedList(list);

            model.SavedJobs = list.Select(x =>
            {
                var m = EntityToViewModel(x);
                return m;
            }).ToList();

            return View(model);
        }

        private SavedJobModel EntityToViewModel(SavedJob entity)
        {
            return new SavedJobModel
            {
                Id = entity.Id,
                CompanyId = entity.CompanyId,
                CompanyName = entity.CompanyName,
                JobTitle = entity.JobTitle,
                Location = entity.Location,
                PublishDays = DateTime.Now.Subtract(entity.StartDate).Days,
                DateSaved = entity.DateSaved,
                EndDate = entity.EndDate,
                JobId = entity.JobId,
                JobPostingId = entity.JobPostingId,
                StartDate = entity.StartDate
            };
        }

    }
}
